﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMS.util;
using System.Resources;
using System.Threading;
using System.Globalization;

namespace SMS.view
{
    public partial class MainForm : Form
    {
        private Form currentForm;
        private String lang = I18nUtil.vnLang;

        public MainForm()
        {
            InitializeComponent();
        }

        private void createStudentMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new CreateStudentForm();
            this.switchForm(currentForm);
        }

        private void registerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new RegistrationForm();
            this.switchForm(currentForm);
        }

        private void createClassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new AddClazzForm();
            this.switchForm(currentForm);
        }

        private void blockToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new AddBlockForm();
            this.switchForm(currentForm);
        }

        private void preferenceToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            currentForm = new PreferenceForm();
            this.switchForm(currentForm);
        }

        private void semesterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new CreateSemesterForm();
            this.switchForm(currentForm);
        }

        private void listOfClassesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new ListOfClassesForm();
            this.switchForm(currentForm);
        }

        private void courseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new CreateCourseForm();
            this.switchForm(currentForm);
        }

		private void inputGradeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new InputGradeForm();
            this.switchForm(currentForm);
        }

        private void reportAllCoursesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new ReportAllCoursesForm();
            this.switchForm(currentForm);
        }

        private void reportAllSemesterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new ReportAllSemestersForm();
            this.switchForm(currentForm);
        }

        private void transcriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentForm = new TranscriptForm();
            this.switchForm(currentForm);
        }

        private void switchForm(Form form)
        {
            this.IsMdiContainer = true;
            this.Height = form.Height + 20;
            this.Width = form.Width;

            form.MdiParent = MainForm.ActiveForm;
            form.WindowState = FormWindowState.Maximized;
            form.Show();
            form.Refresh();
            this.CenterToScreen();
        }

        private void changeLang(String lang)
        {
            I18nUtil.init(lang, new ResourceManager(I18nUtil.resourcePath, typeof(MainForm).Assembly));

            this.Text = I18nUtil.getString("sms");
            menuStudent.Text = I18nUtil.getString("menuStudent");
            createStudentMenuItem.Text = I18nUtil.getString("menuCreateStudent");
            registerToolStripMenuItem.Text = I18nUtil.getString("menuRegistration");
            inputGradeToolStripMenuItem.Text = I18nUtil.getString("inputGrade");
            transcriptToolStripMenuItem.Text = I18nUtil.getString("transcript");

            classMenuItem.Text = I18nUtil.getString("menuClass");
            createClassToolStripMenuItem.Text = I18nUtil.getString("createClass");
            listOfClassesToolStripMenuItem.Text = I18nUtil.getString("listOfClasses");

            reportToolStripMenuItem.Text = I18nUtil.getString("menuReport");
            reportAllCoursesToolStripMenuItem.Text = I18nUtil.getString("reportAllCourses");
            reportAllSemesterToolStripMenuItem.Text = I18nUtil.getString("reportAllSemesters");

            preferenceListToolStripMenuItem.Text = I18nUtil.getString("listOfPreferences");
            blockToolStripMenuItem.Text = I18nUtil.getString("block");
            semesterToolStripMenuItem.Text = I18nUtil.getString("semester");
            courseToolStripMenuItem.Text = I18nUtil.getString("course");
            preferenceToolStripMenuItem1.Text = I18nUtil.getString("preference");

            languageToolStripMenuItem.Text = I18nUtil.getString("language");
            vietnameseToolStripMenuItem.Text = I18nUtil.getString("vietnamese");
            englishToolStripMenuItem.Text = I18nUtil.getString("english");
            logoutToolStripMenuItem.Text = I18nUtil.getString("logout");
        }

        private void changeLangOfParentForm()
        {
            if (currentForm is CreateStudentForm)
            {
                CreateStudentForm form = new CreateStudentForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is RegistrationForm)
            {
                RegistrationForm form = new RegistrationForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is AddClazzForm)
            {
                AddClazzForm form = new AddClazzForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is AddBlockForm)
            {
                AddBlockForm form = new AddBlockForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is PreferenceForm)
            {
                PreferenceForm form = new PreferenceForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is CreateSemesterForm)
            {
                CreateSemesterForm form = new CreateSemesterForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is ListOfClassesForm)
            {
                ListOfClassesForm form = new ListOfClassesForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is CreateCourseForm)
            {
                CreateCourseForm form = new CreateCourseForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is InputGradeForm)
            {
                InputGradeForm form = new InputGradeForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is ReportAllCoursesForm)
            {
                ReportAllCoursesForm form = new ReportAllCoursesForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is ReportAllSemestersForm)
            {
                ReportAllSemestersForm form = new ReportAllSemestersForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
            else if (currentForm is TranscriptForm)
            {
                TranscriptForm form = new TranscriptForm();
                this.switchForm(form);
                form.changeLang(lang);
            }
        }

        private void vietnameseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lang = I18nUtil.vnLang;
            this.changeLang(I18nUtil.vnLang);
            this.Refresh();

            vietnameseToolStripMenuItem.Enabled = false;
            englishToolStripMenuItem.Enabled = true;
            changeLangOfParentForm();
        }

        private void englishToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lang = I18nUtil.usLang;
            this.changeLang(I18nUtil.usLang);
            this.Refresh();
            vietnameseToolStripMenuItem.Enabled = true;
            englishToolStripMenuItem.Enabled = false;
            changeLangOfParentForm();
        }

        private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Dispose();
            LoginForm form = new LoginForm();
            form.ShowDialog();
        }


    }
}
